﻿using HPIT.RentHouse.Admin.Models;
using HPIT.RentHouse.DTO;
using HPIT.RentHouse.IService;
using HPIT.RentHouse.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;

namespace HPIT.RentHouse.Admin.Controllers
{
    [Authorize]
    public class PermissionsController : Controller
    {
        private IPermissionService _permissionService;
        public PermissionsController(IPermissionService permissionService)
        {
            _permissionService = permissionService;
        }

            // GET: Permission
        public ActionResult Index()
        {
            return View();
        }
        public ActionResult Add()
        {
            return View();
        }
        [HttpPost]
        public ActionResult AddPer(PermissionDTO dto)
        {
            var result = _permissionService.Add(dto);
            return Json(result);
        }
        public ActionResult Edit(long id)
        {
            PermissionDTO dto = _permissionService.Get(id);
            return View(dto);
        }
        [HttpPost]
        public ActionResult UpdatePer(PermissionDTO dto)
        {
            var result = _permissionService.Update(dto);
            return Json(result);
        }

        [HttpPost]
        public ActionResult Delete(long id)
        {
            var result = _permissionService.Delete(id);
            return Json(result);
        }

        [HttpPost]
        public ActionResult DeleteBatch(List<long> ids)
        {
            var result = _permissionService.DeleteBatch(ids);
            return Json(result);
        }
        [HttpPost]
        public ActionResult GetList(int start,int length,string name)
        {
            int count = 0;
            var list = _permissionService.GetPagedList(start, length, name, ref count);
            PageModel pageModel = new PageModel();
            pageModel.data = list;
            pageModel.recordsFiltered = count;
            pageModel.recordsTotal = count;
            return Json(pageModel);
        }
        /// <summary>
        /// 退出登录
        /// </summary>
        public ActionResult Logout()
        {
            FormsAuthentication.SignOut();
            return RedirectToAction("Login");
        }
    }
}